package com.ctshk.sapp.finance.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.finance.dto.advance.AdvancePaymentRefundDTO;
import com.ctshk.rpc.finance.dto.advance.AdvancePaymentRefundListDTO;
import com.ctshk.rpc.finance.req.advance.AdvancePaymentApplyListReq;
import com.ctshk.rpc.finance.req.advance.AdvancePaymentApprovalReq;
import com.ctshk.rpc.finance.req.advance.AdvancePaymentRefundAddReq;
import com.ctshk.rpc.finance.req.advance.AdvancePaymentRefundIdReq;
import com.ctshk.rpc.finance.req.bill.RollBackReq;
import com.ctshk.rpc.finance.service.IFinanceAdvancePaymentRefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;

/**
 * <p>
 * 财务退预收款表 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-03-26
 */
@RestController
@Api(value = "退预收款", tags = "退预收款")
@RequestMapping("/finance-advance-payment-refund")
public class FinanceAdvancePaymentRefundController extends BaseController {

    @DubboReference
    private IFinanceAdvancePaymentRefundService advancePaymentRefundService;

    @ApiOperation(value = "列表", notes = "预收管理-查看-退預收款記錄（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "预收管理-查看-退預收款記錄", operDesc = "预收管理-查看-退預收款記錄")
    @PostMapping("/list")
    public Result<PageResponse<AdvancePaymentRefundListDTO>> list(@RequestBody @Valid AdvancePaymentApplyListReq req) {
        return advancePaymentRefundService.list(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "申请", notes = "预收管理-查看-申请退預收款（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.ADD, operTitle = "预收管理-查看-申请退預收款", operDesc = "预收管理-查看-申请退預收款")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid AdvancePaymentRefundAddReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return advancePaymentRefundService.add(req);
    }

    @ApiOperation(value = "提交", notes = "查看退預收款-提交（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "查看退預收款-提交", operDesc = "查看退預收款-提交")
    @PostMapping("/commit")
    public Result commit(@RequestBody @Valid AdvancePaymentRefundIdReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return advancePaymentRefundService.commit(req);
    }

    @ApiOperation(value = "详情", notes = "详情（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "申请退預收款", operDesc = "申请退預收款")
    @PostMapping("/detail")
    public Result<AdvancePaymentRefundDTO> detail(@RequestBody @Valid AdvancePaymentRefundIdReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return advancePaymentRefundService.detail(req);
    }

    @ApiOperation(value = "审批", notes = "审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "审批退預收款", operDesc = "审批退預收款")
    @PostMapping("/approval")
    public Result approval(@RequestBody @Valid AdvancePaymentApprovalReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return advancePaymentRefundService.approval(req);
    }

    @ApiOperation(value = "撤回审批", notes = "撤回审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "撤回申请预收款审批", operDesc = "撤回申请预收款审批")
    @PostMapping("/roll-back")
    public Result rollBack(@RequestBody @Valid RollBackReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return advancePaymentRefundService.rollBack(req);
    }


}
